import request from '#/utils/requestAbort';

// 黑龙江、陕西
export const useNewServers = ['PDBLJ', 'PXBSX'];

// 查询省列表
export async function queryProvinceList(menuCode) {
  return request(`/power/dataPower/common/${menuCode}/t_station`, {
    method: 'GET',
  });
}

// 表格查询
export async function statementInfoList(params) {
  const url = `${
    useNewServers.includes(params.marketId) ? '/private-business' : '/clearing-settlement'
  }/monthStatementInfo/statementInfoList`;
  return request(url, {
    method: 'POST',
    data: params,
  });
}

// 导入
export async function importList(data, marketId) {
  const url = `${
    useNewServers.includes(marketId) ? '/private-business' : '/clearing-settlement'
  }/monthStatementInfo/import`;
  return request(url, {
    method: 'POST',
    data,
  });
}

// 导入省列表获取
// 没有用
export async function getMarketList() {
  const url = `${'/clearing-settlement'}/monthStatementInfo/getMarketList`;
  return request(url, {
    method: 'GET',
  });
}

// 操作日志
export async function logList(params, marketId) {
  const url = `${
    useNewServers.includes(marketId) ? '/private-business' : '/clearing-settlement'
  }/monthStatementInfo/logList`;
  return request(url, {
    method: 'POST',
    data: { ...params, marketId },
  });
}

// 新增
export function addElectricityDetailList(params, marketId) {
  const url = `${
    useNewServers.includes(marketId) ? '/private-business' : '/clearing-settlement'
  }/monthStatementInfo/add`;
  return request(url, {
    method: 'POST',
    data: { ...params, marketId },
  });
}

// 删除
export function delElectricityDetailList(data) {
  const { id, marketId } = data;
  // 使用新服务POST传参
  if (useNewServers.includes(marketId)) {
    return request('/private-business/monthStatementInfo/delete', {
      method: 'POST',
      data,
    });
  }
  return request(`/clearing-settlement/monthStatementInfo/delete/${id}`, {
    method: 'GET',
  });
}

// 修改
export function editElectricityDetailList(params, marketId) {
  const url = `${
    useNewServers.includes(marketId) ? '/private-business' : '/clearing-settlement'
  }/monthStatementInfo/update`;
  return request(url, {
    method: 'POST',
    data: { ...params, marketId },
  });
}

// 通过交易单元id查补贴单价
export function getSubsidyPriceByStationId(stationId, marketId) {
  const url = `${
    useNewServers.includes(marketId) ? '/private-business' : '/clearing-settlement'
  }/monthStatementInfo/getSubsidyPriceByStationId/${stationId}`;
  return request(url, {
    method: 'GET',
  });
}

// 获取合同时段
export function getListContractTimeFrame(marketId) {
  // 黑龙江走字典表
  let url = '/clearing-settlement/monthStatementInfo/listContractTimeFrame';
  if (marketId === 'PDBLJ') {
    url = '/dictionary/dictionaryValue/getDictionaryByCode/CONTRACT_PERIOD_HLJ';
  }
  return request(url, {
    method: 'GET',
  });
}
